package demo.security.example.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * TimeAspect
 *
 * @author lidj
 * @date 2018-01-09
 */
@Aspect
@Component
public class TimeAspect {

    /**
     *
     * @param joinPoint -- 包含拦截的方法信息
     * @return
     */
    @Around("execution(* demo.security.example.web.UserController.*(..))")
    public Object handlerControllerMethod(ProceedingJoinPoint joinPoint)throws Throwable{
        System.out.println("time aspect start");

        long start = System.currentTimeMillis();
        Object[] args = joinPoint.getArgs();
        for (Object arg : args){
            System.out.println("arg is "+arg);
        }
        Object object = joinPoint.proceed();
        System.out.println("aspect 耗时："+(System.currentTimeMillis() - start));

        System.out.println("time aspect finished");

        return object;
    }



    /**
     * 所谓切片无非就是关注如下问题：
     * 切入点
     * 1>在哪些方法上起作用
     * 2>在什么时候起作用
     *
     * 增强
     * 起作用时的业务逻辑---起什么作用
     */
}

